package trabajoISW2.tests;

import java.util.LinkedList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import trabajoISW2.domain.contracts.ICatalog;
import trabajoISW2.domain.exceptions.WrongNameException;
import trabajoISW2.domain.implementations.Book;


public class CatalogTestSuite {

	ICatalog c;
	List<Book> books;
	String n1, n2, n3, n4, n5, n6;
	Book b;
	SuperTest st;
	

	@Before
	public void setup(){
		st = new SuperTest();
		st.inicializa();
		
		c = st.catalog;
		n1 = "1234567890";
		n2 = "1234567890123";
		n3 = "123456789";
		n4 = "12345678901";
		n5 = "123456789012";
		n6 = "12345678901234";
		b = st.book3;
		
	}
	
	//Tests setBooks
	@Test
	public void testSetBook(){
		List<Book> books = new LinkedList<Book>();
		c.setBooks(books);
		books.add(new Book());
		c.setBooks(books);
		books.add(new Book());
		c.setBooks(books);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testSetBook1(){
		c.setBooks(null);
	}
	
	//Tests searchByAuthor
	
	@Test
	public void testSearchByAuthor(){
		c.searchByAuthorId(0);
		c.searchByAuthorId(1);
		c.searchByAuthorId(Integer.MAX_VALUE);
		c.searchByAuthorId(Integer.MAX_VALUE-1);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testSearchByAuthor1(){
		c.searchByAuthorId(-1);
		
	}
	
	//Tests searchByTitle
	
	@Test
	public void testSearchByTitle(){
		c.searchByTitle("prueba");
		
	}
	
	@Test(expected = WrongNameException.class)
	public void testSearchByTitle1(){
		c.searchByTitle("");
		
	}
	
	@Test(expected = WrongNameException.class)
	public void testSearchByTitle2(){
		c.searchByTitle(null);
		
	}
	
	//Tests getBookDetail
	
	@Test
	public void testGetBook(){
		c.getBook(st.book1.getIsbn());
		c.getBook(st.book2.getIsbn());
		
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testGetBookDetail1(){
		c.getBook("");
		
	}
	
	
	
	
		
	
	
	//Tests addBook
	
	@Test
	public void testAddBook(){
		c.addBook(b);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testAddBook1(){
		c.addBook(null);
	}
	
	//Tests removeBook
	
	@Test
	public void testRemoveBook(){
		c.removeBook(b);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testRemoveBook1(){
		c.removeBook(null);
	}
	
}
